# coding=utf-8
class Parent:  # 定义父类
    parentAttr = 100

    def __init__(self):
        print '调用父类的构造函数'

    def parentMethod(self):
        print '调用子类的方法 parentMethod'

    def setAttr(self, attr):
        print '设置父类属性 parentAttr=', attr
        Parent.parentAttr = attr

    def getAttr(self):
        print '父类属性：', Parent.parentAttr
        return Parent.parentAttr

    def sayhello(self):
        print 'hello Parent'


class Child(Parent):  # 定义子类
    def __init__(self):
        Parent.__init__(self)
        print '调用子类的构造函数'

    def childMehtod(self):
        print '调用子类的方法 childMethod'

    def sayhello(self):
        print 'hello child'


from class_inherit import Parent, Child

print '-' * 10, 'Parent Child'
p1 = Parent()
p1.parentMethod()
p1.getAttr()
p1.setAttr(200)
p1.getAttr()
p1.sayhello()
print '-' * 10
p2 = Child()
p2.childMehtod()
p2.parentMethod()
p2.setAttr(300)
p2.getAttr()
p2.sayhello()
